﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
using Acme.Sales.Business.Objects;

namespace TestApplication
{
	public class DALNormalHelper : TimedObjectBase
	{
		private Stopwatch _timer = new Stopwatch();

		public void Select()
		{
			_timer.Reset();
			_timer.Restart();
			Acme.Sales.Business.Objects.CustomerCollection customerCollection = Acme.Sales.Business.Objects.CustomerCollection.RunSelect();
			_timer.Stop();
			System.Diagnostics.Debug.WriteLine(_timer.Elapsed.TotalMilliseconds);
			this.OnComplete(new TimedEventArgs("Normal DAL Select All", (long)_timer.Elapsed.TotalMilliseconds));

			_timer.Reset();
			_timer.Restart();
			customerCollection = Acme.Sales.Business.Objects.CustomerCollection.RunSelect(x => x.FirstName == "John");
			_timer.Stop();
			System.Diagnostics.Debug.WriteLine(_timer.Elapsed.TotalMilliseconds);
			this.OnComplete(new TimedEventArgs("Normal DAL Select By First Name", (long)_timer.Elapsed.TotalMilliseconds));

			_timer.Reset();
			_timer.Restart();
			customerCollection = Acme.Sales.Business.Objects.CustomerCollection.RunSelect(x => x.CreatedDate > new DateTime(2010, 1, 1));
			_timer.Stop();
			System.Diagnostics.Debug.WriteLine(_timer.Elapsed.TotalMilliseconds);
			this.OnComplete(new TimedEventArgs("Normal DAL Select By CreatedDate", (long)_timer.Elapsed.TotalMilliseconds));

		}

		public void Insert()
		{
			CustomerCollection customerCollection = new CustomerCollection();

			_timer.Reset();
			_timer.Restart();
			for (int ii = 0; ii < TesterClass.RECORD_COUNT; ii++)
			{
				Customer customer = customerCollection.NewItem();
				customer.Address = "123 Elm Street";
				customer.City = "Atlanta";
				customer.Phone = "999-999-9999";
				customer.FirstName = "John";
				customer.LastName = "Doe";
				customerCollection.AddItem(customer);
			}

			customerCollection.Persist();
			_timer.Stop();
			System.Diagnostics.Debug.WriteLine(_timer.Elapsed.TotalMilliseconds);
			this.OnComplete(new TimedEventArgs("Normal DAL Insert", (long)_timer.Elapsed.TotalMilliseconds));

		}

		public void Delete()
		{
			_timer.Reset();
			_timer.Restart();
			CustomerCollection.DeleteData(x => true);
			_timer.Stop();
			System.Diagnostics.Debug.WriteLine(_timer.Elapsed.TotalMilliseconds);
			this.OnComplete(new TimedEventArgs("Normal DAL Delete All", (long)_timer.Elapsed.TotalMilliseconds));
		}

		public void Update()
		{
		}


	}
}
